home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / sys_util / moduleap / form1.txt < prev    next >
Encoding:
Text File  |  1991-07-13  |  2.9 KB  |  108 lines

  1.                        
  2.  
  3. Sub Form_Click ()
  4.     Refresh
  5.     CurrentX = 0
  6.     CurrentY = 0
  7.     
  8.     FileName$ = GetFileName$((hWnd), h%)
  9.     Print "File Name"; Tab(20); "= "; FileName$
  10.     Print "Module Handle"; Tab(20); "= "; Hex$(h%)
  11.  
  12.     A% = GetInstanceCount%((hWnd))
  13.     Print "Instance Count"; Tab(20); "= "; A%
  14.     
  15.     NextInstance% = FindSecondInstance%((hWnd))
  16.  
  17.     If NextInstance% Then
  18.         w% = SetActiveWindow(NextInstance%)
  19.     End If
  20.     
  21.     '|| Code to change Task List entry...
  22.     'parenttext$ = "Hello " + parenttext$
  23.     'y% = SetWindowText(GetWindow(hWnd, GW_OWNER), parenttext$)
  24. End Sub
  25.  
  26.  
  27. Function ActivateNextWindow% ()
  28.     Owner% = GetWindow(hWnd, GW_OWNER)
  29.     h% = GetClassWord(Owner%, GCW_HMODULE)
  30.     Start$ = Space$(128)
  31.     Other$ = Space$(128)
  32.     y% = GetModuleFileName(h%, Start$, Len(Start$))
  33.     Print Owner%, Start$
  34.     A% = Owner%
  35.     Do
  36.         Other$ = Space$(128)
  37.         A% = GetWindow(A%, GW_HWNDNEXT)
  38.         If A% = 0 Then
  39.             A% = GetWindow(Owner%, GW_HWNDFIRST)
  40.         End If
  41.         yH% = GetClassWord(A%, GCW_HMODULE)
  42.         Handle% = A%
  43.         yH% = GetModuleFileName(yH%, Other$, Len(Other$))
  44.         Print " Found  = "; Hex$(A%); "  "; Other$
  45.     Loop Until Other$ = Start$
  46.     Print Hex$(Handle%); "  "; Other$
  47.     ActivateNextWindow% = Handle%
  48. End Function
  49.  
  50. Function GetFileName$ (WindowHandle As Integer, ModuleHandle As Integer)
  51.     Dim FileName        As String
  52.     Dim FileNameLength  As Integer
  53.  
  54.     If WindowHandle Then
  55.         ModuleHandle = GetClassWord(WindowHandle, GCW_HMODULE)
  56.     End If
  57.  
  58.     FileName = Space$(128)
  59.     
  60.     FileNameLength = GetModuleFileName(ModuleHandle, FileName, Len(FileName))
  61.     
  62.     FileName = Left$(FileName, FileNameLength)
  63.  
  64.     GetFileName$ = FileName
  65. End Function
  66.  
  67. Function GetInstanceCount% (WindowHandle As Integer)
  68.     Dim InstanceCount   As Integer
  69.     Dim ModuleHandle    As Integer
  70.  
  71.     ModuleHandle = GetClassWord(WindowHandle, GCW_HMODULE)
  72.     InstanceCount = GetModuleUsage(ModuleHandle)
  73.     
  74.     GetInstanceCount% = InstanceCount
  75. End Function
  76.  
  77. Function FindSecondInstance% (WindowHandle As Integer)
  78.     Dim WhoAreWe        As String
  79.     Dim HowManyAreWe    As Integer
  80.     Dim OurModule       As Integer
  81.  
  82.     Dim WhoAreWeAt      As String
  83.     Dim SomeWindow      As Integer
  84.  
  85.     WhoAreWe = GetFileName$(WindowHandle, OurModule)
  86.     HowManyAreWe = GetInstanceCount%(WindowHandle)
  87.  
  88.     If HowManyAreWe < 2 Then
  89.         FindSecondInstance% = 0
  90.         Exit Function
  91.     End If
  92.  
  93.     SomeWindow = WindowHandle
  94.  
  95.     Do
  96.         WhoAreWeAt = Space$(128)
  97.         SomeWindow = GetWindow(SomeWindow, GW_HWNDNEXT)
  98.         
  99.         If SomeWindow = 0 Then SomeWindow = GetWindow(WindowHandle, GW_HWNDFIRST)
  100.  
  101.         WhoAreWeAt = GetFileName$((0), SomeWindow)
  102.         
  103.     Loop Until WhoAreWe = WhoAreWeAt
  104.  
  105.     FindSecondInstance% = SomeWindow
  106. End Function
  107.  
  108.